package com.zx.controller;


import com.zx.pojo.SmbmsBill;
import com.zx.pojo.SmbmsUser;
import com.zx.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("/bill/")
public class BillController {
    //控制器层调用service层
    @Autowired
    private BillService billService;

    //查询
    @RequestMapping("list")
    public String list(Model model) {
        List<SmbmsBill> ubilllist=billService.findAllByBill();
        model.addAttribute("ubilllist",ubilllist);
        return "billlist";
    }

    @RequestMapping("goupdate")
    public String goupdate(Long uid,Model model){
       SmbmsBill smbmsBill= billService.findBillById(uid);
       model.addAttribute("ebill",smbmsBill);
        return "billmodify";
    }

    @RequestMapping("doupdate")
    public String doupdate(SmbmsBill smbmsBill, Model model){
        boolean flag=billService.updateBill(smbmsBill);
        if (flag){
            return "forward:list";
        }else {
            model.addAttribute("msg","修改失败！");
            return "billlist";
        }
    }

    @RequestMapping("del")
    public String del(Long uid,Model model){
        boolean flag = billService.delBill(uid);
        if (flag){
            return "forward:list";
        }else {
            model.addAttribute("msg","删除失败");
            return "billlist";

        }
    }

    @RequestMapping("details/{id}")
    public String details(@PathVariable("id") long uid,Model model){
        SmbmsBill smbmsBill = billService.findBillById(uid);
        model.addAttribute("dbill",smbmsBill);
        return "billview";
    }

    @RequestMapping("save")
    public String save(SmbmsBill smbmsBill,Model model){
        boolean flag = billService.addBill(smbmsBill);
        if (flag){
            return "forward:list";
        }else {
            model.addAttribute("msg","删除失败！");
            return "billlist";
        }
    }

}
